package com.itfenghuang.day06;

import com.itfenghuang.bean.Cla;
import com.itfenghuang.bean.Stu;
import com.itfenghuang.bean.User;
import com.itfenghuang.day06.mapper.ClaMapper;
import com.itfenghuang.day06.mapper.ScMapper;
import com.itfenghuang.day06.mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
@SuppressWarnings("all")
public class Userservice {
    @Test
    public void test() throws IOException {
        InputStream is = Resources.getResourceAsStream("MyBatisConfig.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = factory.openSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        List<User> list = mapper.selectUsers();
        System.out.println(list);
        sqlSession.close();
        is.close();
    }
    @Test
    public void test1() throws IOException {
        InputStream is = Resources.getResourceAsStream("MyBatisConfig.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = factory.openSession();
        ClaMapper mapper = sqlSession.getMapper(ClaMapper.class);
        List<Cla> clas = mapper.selectAllCla();
        System.out.println(clas);
        sqlSession.close();
        is.close();
    }
    @Test
    public void test2() throws IOException {
        InputStream is = Resources.getResourceAsStream("MyBatisConfig.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = factory.openSession();
        ScMapper mapper = sqlSession.getMapper(ScMapper.class);
        Stu stu = mapper.selectByStuAndCourse("张三");
        System.out.println(stu);
        sqlSession.close();
        is.close();
    }
}
